﻿ 
<!DOCTYPE html>  
<html>  
<head>  
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
    <meta name="keywords" content="跟进中客户">  
    <meta name="description" content="跟进中客户">  
    <title>跟进中客户管理</title>  
    
    <%@ include file="/WEB-INF/inc/default.jsp"%>
    <jsp:include page="/WEB-INF/inc/dic.jsp"/>    

</head>  
<body>  
    
      
    <table id="dg" title="跟进中客户管理" class="easyui-datagrid" style="height:550px" 
            url="/customer/customer/bdcustomerlist.do"  
            toolbar="#toolbar" pagination="true"  
            rownumbers="true" fitColumns="true" pageSize="20" loadMsg="正在查询,请稍候..." singleSelect="true">  

    </table>  
    <div id="toolbar">  
    	  <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="add()">添加</a>  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newBD()">新增</a>  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="edit()">修改</a>  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="deletes()">删除</a>  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="find()">查询</a>
    </div>  
      
   
      
    <!-- query form窗体(开始) -->              
    <div id="dlg_query" style="display:none;">  
    	  <!--
        <div itemId="tab_panel"  class="easyui-tabs" style="width:700px;height:300px">
    	        <div title="基本查询"  style="padding:10px"> 
                  <div class="ftitle">公司</div>  
                  <form itemId="fmquery" method="post" novalidate>                            
	                  		     <div class="fitem">  
                               <label style="width:100px">名称:</label>                                            
                               <input name="name" class="easyui-box">                       
                             </div> 
	                  		     <div class="fitem">  
                               <label style="width:100px">关键字:</label>                                            
                               <input name="keyword" class="easyui-box">                       
                             </div> 
                             <div class="fitem">  
                               <label style="width:100px">一级行业:</label>                                            
                               <input class="easyui-combobox" name="industry_parent" style="width:200px;"  data-options="data:__getCategoryByParant('INDUSTRY', 0),valueField:'id', textField:'codeNameCn', multiple:false,panelHeight:'auto',mode:'remote'
		                             	,onSelect: function(rec){              
                                      $('#second_industry').combobox('loadData', __getCategoryByParant('INDUSTRY', rec.id));  
                                      $('#second_industry').combobox('setValue',null);
                                   }
			                          ">
                             </div> 
                             <div class="fitem">  
                               <label style="width:100px">二级行业:</label>                                            
                               <input class="easyui-combobox" id="second_industry"  name="industry" style="width:200px;"  data-options="data:__getCategory('INDUSTRY'),valueField:'id', textField:'codeNameCn', multiple:false,panelHeight:'auto',mode:'remote' ">                     
                             </div> 
	                  		     <div class="fitem">  
                               <label style="width:100px">公司类型:</label>                                                                           
                               <input class="easyui-combobox"  name="companyType" style="width:50px;"  data-options="data:__getConstantCategory('companyType'),valueField:'code', textField:'value', multiple:false,panelHeight:'auto',mode:'remote' ">
                             </div>
	                  		     
	                </form>
	                
             </div>  
             <div title="高级查询"  style="padding:10px"> 
                  <div class="ftitle">公司</div>  
                  <form itemId="fmquery" method="post" novalidate>       
                        <table style="width:100%">
                             <tr>
                                  <td>城市</td>
                                  <td><input class="easyui-combobox" name="location"  style="width:200px;"  data-options="data:__getCategory('LOCATION'),valueField:'id', textField:'codeNameCn', multiple:false,panelHeight:'auto',mode:'remote' "></td>
                                  <td >人员规模</td>
                                  <td><input class="easyui-combobox" name="size" style="width:200px;"  data-options="data:__getCategory('COMPANY_SIZE'),valueField:'id', textField:'codeNameCn', multiple:false,panelHeight:'auto',mode:'remote' "></td>
                             </tr>
                             <tr>
                                  <td>电话总机</td>
                                  <td ><input name="tel" class="easyui-box" required="true"></td>
                                  <td >地址</td>
                                  <td><input name="address" class="easyui-box"></td>
                             </tr>
                             <tr>
                                  <td>邮编</td>
                                  <td ><input name="postcode" class="easyui-box"></td>
                                  <td >公司性质</td>
                                  <td><input class="easyui-combobox" name="property" style="width:200px;" data-options="data:__getCategory('COMPANY_NATURE'),valueField:'id', textField:'codeNameCn', multiple:false,panelHeight:'auto',mode:'remote' "></td>
                             </tr>
                             <tr>
                                  <td>机构类型</td>
                                  <td ><input class="easyui-combobox" name="type" style="width:200px;"  data-options="data:__getCategory('ORGANIZATION_TYPE'),valueField:'id', textField:'codeNameCn', multiple:false,panelHeight:'auto',mode:'remote' "></td>
                                  <td >公司产品</td>
                                  <td><input name="product" class="easyui-box"></td>
                             </tr>
                              
	                  		</table>      
	                </form>
	                
            </div>    
            
        </div>
        <div  style="text-align:center">  
                    <a href="javascript:void(0)" itemId="btn-query" class="easyui-linkbutton" iconCls="icon-ok" ">查询</a>  
                    <a href="javascript:void(0)" itemId="btn-close" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>  
        </div>    
        -->
    </div> 
    <!-- query form窗体(结束) -->  

    <div id="dlg-buttons-query">  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="query()">确定</a>  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg_query').dialog('close')">Cancel</a>  
    </div>  
    
    
    <script type="text/javascript">  
        var url;  
        var companyId=0;
        var custId=0;
        
        var addWin;
        var editWin;
        var selectAddWin;
         var confWin;
        function add(){         	 
            //$('#wSelectCompany').dialog('open').dialog('setTitle','新增BD客户');  
            // $('#wSelectCompany').window('open');
   	        // $('#wSelectCompany').find('iframe')[0].contentWindow.location.href="/customer/company/selectCompanyPage.do";
            //$('#fm').form('clear');
            
            if (selectAddWin)
                 selectAddWin.window('open');
             else selectAddWin = $.window({
		      	   	title:"添加跟进中客户",
		      	   	url:"/customer/company/selectCompanyPage.do",
		      	   	isIframe:true,
		      	   	height:400,
		      	   	modal:false,		      	   	
		      	   	width:1050,
		      	   	onComplete:function(jq,iframe){	
		      	   		         	   		   	      	   		
		      	   		   var fwindow = $.window.util.getFrameWindow(iframe);		      	   		
		      	   		   var ijq = fwindow.jQuery;		
		      	   		   var curWin=this;   
		      	   		   
		      	   		   var curWin=this;
					
					           fwindow.closeWin=function(){
					           	   curWin.window('close');
					           	  
				             };
				             
				             fwindow.callback=curWin.openerWin.addCompanyDB;
				             //fwindow.pcallback=curWin.openerWin.addCompanyDB;
		      	   		   //alert(fwindow.pcallback2);
		      	   	}
		      	});
		      	selectAddWin.openerWin=window;  
            //url = '/customer/company/save.do';  
        } 
        function newBD(){         	 
            //$('#dlg').dialog('open').dialog('setTitle','新增BD客户');  
            //$('#fm').form('clear');
            
              
            if (addWin)
                 addWin.window('open');
             else addWin = $.window({
		      	   	title:"新增跟进中客户",
		      	   	url:"/customer/company/companyAdd.do?type=BD",
		      	   	isIframe:true,
		      	   	height:600,
		      	   	modal:false,		      	   	
		      	   	width:1000,
		      	   	onComplete:function(jq,iframe){	
		      	   		         	   		   	      	   		
		      	   		   var fwindow = $.window.util.getFrameWindow(iframe);		      	   		
		      	   		   var ijq = fwindow.jQuery;		
		      	   		   var curWin=this;   
		      	   		   
		      	   		   var curWin=this;
					
					           fwindow.closeWin=function(){
					           	   curWin.window('close');
				             };
				             fwindow.refresh=function(){
					           	   if(curWin.openerWin.refresh) curWin.openerWin.refresh();
				             };
		      	   		   
		      	   	}
		      	});
		      	addWin.openerWin=window; 
        }  
        function doEdit(companyId,custId){  
        	   editWin = $.window({
		      	   	title:"修改跟进中客户公司",
		      	   	url:"/customer/customer/customerEdit.do?type=UPDATE&companyId="+companyId+"&custId="+custId,
		      	   	isIframe:true,
		      	   	isCloseDestroy:true,
		      	   	height:650,
		      	   	modal:false,
		      	   	minimizable : true,
		      	   	width:1200,
		      	   	onComplete:function(jq,iframe){		      	   		
		      	   		   var fwindow = $.window.util.getFrameWindow(iframe);		      	   		
		      	   		   var ijq = fwindow.jQuery;		
		      	   		   var curWin=this;   
		      	   		   
		      	   		   fwindow.closeWin=function(){
					           	   curWin.window('close');
				             };
				             fwindow.refresh=function(){
					           	   curWin.openerWin.refresh();
				             };
		      	   		       	   		
		      	   		  
		      	   	}
		          	});
		      	    editWin.openerWin=window; 
        } 	
        function edit(){  
            //var row = $('#dg').datagrid('getSelected');  
            var rows = $('#dg').datagrid('getSelections');
            if (!rows||rows.length==0){
            	 $.messager.alert('提示','请选择要修改的行','info');
            	 return;
            }
            if (!rows||rows.length>1){
            	 $.messager.alert('提示','不能选择多行','info');
            	 return;
            }
            if (rows){  
                //$('#dlg_edit').dialog('open').dialog('setTitle','修改跟进中客户');  
                //$('#fm').form('load',rows[0]);  
                //var tab=$('#tab_panel').tabs('getTab', 0);
        	      companyId=rows[0].companyId;
        	      custId=rows[0].id;
        	      doEdit(companyId,custId);
        	    	//tab.find('iframe')[0].contentWindow.location.href=tab.attr('url')+"?url=/customer/company/update.do&companyId="+companyId;
        	    	
                //$('#fm').form('load','/customer/company/get.do?id='+rows[0].id);  
                //url = '/customer/company/update.do';
            }  
        }  
         function refresh(){        	 
        	  $('#dg').datagrid('reload');
         }	
        function save(){          	   
        	  if (!$('#fm').form('validate')) return; 
            $('#fm').form('submit',{  
                url: url,  
                onSubmit: function(){  
                    return $(this).form('validate');  
                },  
                success: function(result){  
                    var result = eval('('+result+')');  
                    console.log(result);
                    if (result.success == true){  
                        $.messager.alert('信息',result.msg,'info');  
                        $('#dlg').dialog('close');      // close the dialog  
                        $('#dg').datagrid('reload');    // reload the user data  
                    } else {  
                        $.messager.alert('错误',result.msg,'error');
                    }  
                }  
            });  
        }  
        function deletes(){  
            var row = $('#dg').datagrid('getSelected');  
            
            var rows = $('#dg').datagrid('getSelections');  

            if (!rows||rows.length==0){
            	 $.messager.alert('提示','请选择要删除的行','info');
            	 return;
            }
            if (rows){  
                $.messager.confirm('重要提示','确定要删除?',function(r){  
                    if (r){  
                        $.post('/customer/company/delete.do',{ids:getRecordArray(rows,'id').join(',')},function(result){  
                            if (result.success){  
                                $('#dg').datagrid('reload');    // reload the user data  
                            } else {  
                                 
                                $.messager.alert('错误',result.msg,'error'); 
                            }  
                        },'json');  
                    }  
                });  
            }  
        }  
        function find(){  
              
                  if (confWin)
     	        confWin.window('open');
			    else confWin = $.window({
			    	title:"查询",
			    	tplRef:"dlg_query",//这个属性指定模板id
			    	height:380,
			    	width:730,	
			    	onComplete:function(){
			    		//窗口里面的初始化,最好是在这个事件里面进行
			    		var curWin=this;
			    		
			    		
			    		this.find('a[itemId="btn-query"]').click(function(){
			    		
			    			  if (!curWin.curForm) curWin.curForm=curWin.find('form[itemId="fmquery"]');
			    			  //console.log(curWin.curForm);
			    			  curWin.window('close');
			    			  var formdata=curWin.curForm.formToArray();   		 
		              curWin.openerWin.query(formdata);
			    		});
			    		this.find('a[itemId="btn-close"]').click(function(){
			    			  curWin.window('close');
			    	  });
			    	  
			    	  
			    	  this.find('div[itemId="tab_panel"]').tabs({
        	          onSelect: function(title,index){        	          
        	          	var tab=curWin.find('div[itemId="tab_panel"]').tabs('getTab', index);        	          
        	          	curWin.curForm=tab.find('form[itemId="fmquery"]');  
        	          	//console.log(curWin.curForm);
        	          	        	          	
        	          }
             }); 
			    	  
			    		
			    	}
			    });
			    confWin.openerWin=window;
              
        } 
        	
        function query(formdata){  
                
                $('#dg').datagrid({
	                  queryParams: array2json(formdata)
                });
              
        }
        
        //生成grid的字段,需要字典的自动转换
        $('#dg').datagrid({
        	   columns:[[
        	   	
        	   	   {field:'id',title:'公司编号', width:100}
        	   	   ,{field:'abbrName',title:'公司简称', width:100}
        	   	   ,{field:'name',title:'公司中文名', width:100,hidden : true}
        	   	   ,{field:'fullName',title:'公司英文名', width:100,hidden : true}        	   	   
        	   	   ,{field:'industry',title:'行业', width:100,
        	   		      formatter: function(value,row,index){
        	   		      	return __getCategroyCodeValue('INDUSTRY', value);
        	   		      }
        	   	     }
        	   	   ,{field:'property',title:'公司性质', width:100,
        	   		      formatter: function(value,row,index){
        	   		      	return __getCategroyCodeValue('COMPANY_NATURE', value);
        	   		      },hidden : true
        	   	     }
        	   	   ,{field:'bdAccount',title:'跟进人', width:100} 
        	   	   ,{field:'expiredD',title:'保护到期日', width:100}
        	   	   ,{field:'type',title:'机构类型', width:100,
        	   		      formatter: function(value,row,index){
        	   		      	return __getCategroyCodeValue('ORGANIZATION_TYPE', value);
        	   		      }
        	   	     }
        	   	   ,{field:'tel',title:'电话总机', width:100}
        	   	   ,{field:'website',title:'网站', width:100,hidden : true}
        	   	   ,{field:'location',title:'城市', width:100,
        	   		      formatter: function(value,row,index){
        	   		      	return __getCategroyCodeValue('LOCATION', value);
        	   		      }
        	   	     }
        	   	   ,{field:'address',title:'地址', width:100,hidden : true}
        	   	   ,{field:'postcode',title:'邮编', width:100,hidden : true}
        	   	   ,{field:'profile',title:'公司简介', width:100}
        	   	   ,{field:'jobProfile',title:'公司职位简介', width:100}
        	   	   ,{field:'capital',title:'资本结构描述', width:100,hidden : true}
        	   	   ,{field:'background',title:'公司背景', width:100,hidden : true}
        	   	   ,{field:'product',title:'公司业务/产品', width:100,hidden : true}
        	   	   
        	   	   ,{field:'regCapital',title:'注册资本', width:100,hidden : true}
        	   	   
        	   	   ,{field:'creator',title:'创建人', width:100,hidden : true}
        	   	   ,{field:'createDt',title:'创建时间', width:100,hidden : true}
        	   	   ,{field:'modifier',title:'修改人', width:100,hidden : true}
        	   	   ,{field:'modifiedDt',title:'修改时间', width:100,hidden : true}
        	   	  
        	   	   
        	   	   
        	   	
        	   	
        	   ]]
        	   ,onDblClickRow: function(rowIndex, rowData){
        	    	//$('#dlg-edit').dialog('open').dialog('setTitle','修改BD公司');                  
                //$('#fm').form('load','/customer/company/get.do?id='+rowData.companyId);  
                var tab=$('#tab_panel').tabs('getTab', 0);
        	      companyId=rowData.companyId;
        	      custId=rowData.id;
        	      
        	      doEdit(companyId,custId);
        	      //$('#dlg_edit').dialog('open').dialog('setTitle','修改BD客户');
        	    	//tab.find('iframe')[0].contentWindow.location.href=tab.attr('url')+"?url=/customer/company/update.do&companyId="+companyId;
                //$('#fm').form('load','/customer/company/get.do?id='+rowData.id); 
                //url = '/customer/company/update.do';        	    	
        	    }
        }); 
        //完成-生成grid的字段
        
        
       $('#tab_panel').tabs({
        	    onSelect: function(title,index){
        	    
        	    	var tab=$('#tab_panel').tabs('getTab', index);
        	      if (tab.attr('url')=='/customer/customerCrm/list.do'||tab.attr('url')=='/customer/customer/financeInfo.do'||tab.attr('url')=='/customer/customerComplain/managerPage.do'||tab.attr('url')=='/project/contractJob/customerJob.do')
        	        tab.find('iframe')[0].contentWindow.location.href=tab.attr('url')+"?custId="+custId;
        	      else 	
        	    	   tab.find('iframe')[0].contentWindow.location.href=tab.attr('url')+"?companyId="+companyId;
        	    	console.log(tab.find('iframe')[0].contentWindow.src);
        	    	
        	    }
        }); 
        
      
      function addCompanyDB(company,callback){
      	
      	$.post('/customer/customerBd/companysave.do',{companyIds:company.id},function(result){  
                            if (result.success){  
                                $('#dg').datagrid('reload');    // reload the user data  
                                //$.messager.alert('信息',result.msg,'info');
                                alert(result.msg);
                                if (callback) callback;
                            } else {  
                                 
                                //$.messager.alert('错误',result.msg,'error'); 
                                alert(result.msg);
                            }  
               },'json');
      } 
    </script>  
     
     

     
     
     
</body>  
</html>